﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Diagnostics;

namespace UtilZ.Dotnet.Ex.Base
{
    /// <summary>
    /// Convert类型扩展方法类
    /// </summary>
    public static partial class ConvertEx
    {


        /// <summary>
        /// 进制转换基准值
        /// </summary>
        private const int _BASE = 2;


        #region ConvertToBitValues

        /// <summary>
        /// 获取byte位值数组
        /// </summary>
        /// <param name="value">byte</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(byte value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            string byteStr = Convert.ToString(value, _BASE);
            return PrimitiveGetBitValues(byteStr, sizeof(byte), cpuType);
        }

        /// <summary>
        /// 获取sbyte位值数组
        /// </summary>
        /// <param name="value">sbyte</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(sbyte value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            string byteStr = Convert.ToString(value, _BASE);
            return PrimitiveGetBitValues(byteStr, sizeof(sbyte), cpuType);
        }



        /// <summary>
        /// 获取short位值数组
        /// </summary>
        /// <param name="value">short</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(short value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            string byteStr = Convert.ToString(value, _BASE);
            return PrimitiveGetBitValues(byteStr, sizeof(short), cpuType);
        }

        /// <summary>
        /// 获取ushort位值数组
        /// </summary>
        /// <param name="value">ushort</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(ushort value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            string byteStr = Convert.ToString(value, _BASE);
            return PrimitiveGetBitValues(byteStr, sizeof(ushort), cpuType);
        }



        /// <summary>
        /// 获取int位值数组
        /// </summary>
        /// <param name="value">int</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(int value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            string byteStr = Convert.ToString(value, _BASE);
            return PrimitiveGetBitValues(byteStr, sizeof(int), cpuType);
        }

        /// <summary>
        /// 获取uint位值数组
        /// </summary>
        /// <param name="value">uint</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(uint value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            string byteStr = Convert.ToString(value, _BASE);
            return PrimitiveGetBitValues(byteStr, sizeof(uint), cpuType);
        }



        /// <summary>
        /// 获取long位值数组
        /// </summary>
        /// <param name="value">long</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(long value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            string byteStr = Convert.ToString(value, _BASE);
            return PrimitiveGetBitValues(byteStr, sizeof(long), cpuType);
        }


        /// <summary>
        /// 获取ulong位值数组
        /// </summary>
        /// <param name="value">ulong</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(ulong value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            byte[] bytes = BitConverter.GetBytes(value);
            return PrimitiveGetBitValues(bytes, sizeof(ulong), cpuType);
        }

        /// <summary>
        /// 获取float位值数组
        /// </summary>
        /// <param name="value">float</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(float value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            byte[] bytes = BitConverter.GetBytes(value);
            return PrimitiveGetBitValues(bytes, sizeof(float), cpuType);
        }

        /// <summary>
        /// 获取double位值数组
        /// </summary>
        /// <param name="value">double</param>
        /// <param name="cpuType">CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>位值数组</returns>
        public static byte[] ToBitValues(double value, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            byte[] bytes = BitConverter.GetBytes(value);
            return PrimitiveGetBitValues(bytes, sizeof(double), cpuType);
        }


        private static byte[] PrimitiveGetBitValues(byte[] bytes, int size, CPUTypes cpuType)
        {
            byte[] bitValueArr = new byte[size * 8];
            int offset = 0;
            byte[] buffer;

            var envType = EnvironmentEx.CpuType;
            if (envType == CPUTypes.LittleEndian)
            {
                for (int i = bytes.Length - 1; i >= 0; i--)
                {
                    buffer = ToBitValues(bytes[i], cpuType);
                    Array.Copy(buffer, 0, bitValueArr, offset, buffer.Length);
                    offset += buffer.Length;
                }
            }
            else
            {
                for (int i = 0; i < bytes.Length; i++)
                {
                    buffer = ToBitValues(bytes[i], cpuType);
                    Array.Copy(buffer, 0, bitValueArr, offset, buffer.Length);
                    offset += buffer.Length;
                }
            }

            if (envType != cpuType)
            {
                bitValueArr = bitValueArr.Reverse().ToArray();
            }

            return bitValueArr;
        }


        private static byte[] PrimitiveGetBitValues(string byteStr, int size, CPUTypes cpuType)
        {
            int length = size * 8;
            var envType = EnvironmentEx.CpuType;
            byte[] bitValueArr = new byte[length];
            if (envType == CPUTypes.LittleEndian)
            {
                //小端
                if (byteStr.Length < length)
                {
                    byteStr = byteStr.Insert(0, new string('0', length - byteStr.Length));
                }
            }
            else
            {
                //大端
                byteStr = String.Join(string.Empty, byteStr.Reverse());//大端测试代码
                if (byteStr.Length < length)
                {
#pragma warning disable IDE0054
                    byteStr = byteStr + new string('0', length - byteStr.Length);
                }
            }

            for (int i = 0; i < length; i++)
            {
                bitValueArr[i] = byte.Parse(byteStr[i].ToString());
            }

            if (envType != cpuType)
            {
                bitValueArr = bitValueArr.Reverse().ToArray();
            }

            return bitValueArr;
        }

        #endregion




        #region 二进制bit字符串转换为指定类型的值

        /// <summary>
        /// 二进制bit字符串转换为byte
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static byte BitStrToByte(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(byte), str, cpuType);
            return Convert.ToByte(str, _BASE);
        }

        /// <summary>
        /// 二进制bit字符串转换为sbyte
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static sbyte BitStrToSByte(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(sbyte), str, cpuType);
            return Convert.ToSByte(str, _BASE);
        }


        /// <summary>
        /// 二进制bit字符串转换为short
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static short BitStrToInt16(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(short), str, cpuType);
            return Convert.ToInt16(str, _BASE);
        }

        /// <summary>
        /// 二进制bit字符串转换为ushort
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static ushort BitStrToUInt16(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(ushort), str, cpuType);
            return Convert.ToUInt16(str, _BASE);
        }



        /// <summary>
        /// 二进制bit字符串转换为int
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static int BitStrToInt32(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(int), str, cpuType);
            return Convert.ToInt32(str, _BASE);
        }

        /// <summary>
        /// 二进制bit字符串转换为uint
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static uint BitStrToUInt32(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(uint), str, cpuType);
            return Convert.ToUInt32(str, _BASE);
        }

        /// <summary>
        /// 二进制bit字符串转换为long
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static long BitStrToInt64(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(long), str, cpuType);
            return Convert.ToInt64(str, _BASE);
        }

        /// <summary>
        /// 二进制bit字符串转换为ulong
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static ulong BitStrToUInt64(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(ulong), str, cpuType);
            return Convert.ToUInt64(str, _BASE);
        }


        /// <summary>
        /// 二进制bit字符串转换为float
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static float BitStrToSingle(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(float), str, cpuType);
            byte[] buffer = GetConvertToBytes(str, cpuType);
            return BitConverter.ToSingle(buffer, 0);
        }


        /// <summary>
        /// 二进制bit字符串转换为double
        /// </summary>
        /// <param name="str">二进制bit字符串</param>
        /// <param name="cpuType">二进制bit字符串对应的CPU类型:
        /// CPUTypes.LittleEndian:小端,数据索引由0开始递增,依次为从高位到低位;
        /// false:大端,数据索引由0开始递增,依次为从低位到高位</param>
        /// <returns>转换结果</returns>
        public static double BitStrToDouble(string str, CPUTypes cpuType = CPUTypes.LittleEndian)
        {
            str = FormatBitString(sizeof(double), str, cpuType);
            byte[] buffer = GetConvertToBytes(str, cpuType);
            return BitConverter.ToDouble(buffer, 0);
        }

        private static byte[] GetConvertToBytes(string str, CPUTypes cpuType)
        {
            const int LEN = 8;
            int count = str.Length / LEN;
            byte[] buffer = new byte[count];
            int startIndex = 0;
            string tmpStr;

            for (int i = 0; i < count; i++)
            {
                tmpStr = str.Substring(startIndex, LEN);
                startIndex += LEN;
                buffer[i] = BitStrToByte(tmpStr, cpuType);
            }

            return buffer;
        }

        private static string FormatBitString(int size, string str, CPUTypes cpuType)
        {
            int length = size * 8;
            if (str.Length < length)
            {
                if (cpuType == CPUTypes.LittleEndian)
                {
                    str = new string('0', length - str.Length) + str;
                }
                else
                {
                    str = str + new string('0', length - str.Length);
                }
            }

            if (EnvironmentEx.CpuType != cpuType)
            {
                str = string.Join(string.Empty, str.Reverse());
            }

            return str;
        }
        #endregion




        #region bit数据与整数之间相互转换

        #region 整数转换为bit数组
        /// <summary>
        /// sbyte转换为bit数组
        /// </summary>
        /// <param name="value">sbyte值</param>
        /// <returns>bit数组</returns>
        public static byte[] IntegerToBits(sbyte value)
        {
            return PrimitiveIntegerToBits(Convert.ToString(value, 2), sizeof(sbyte));
        }

        /// <summary>
        /// byte转换为bit数组
        /// </summary>
        /// <param name="value">byte值</param>
        /// <returns>bit数组</returns>
        public static byte[] IntegerToBits(byte value)
        {
            return PrimitiveIntegerToBits(Convert.ToString(value, 2), sizeof(byte));
        }


        /// <summary>
        /// Int16转换为bit数组
        /// </summary>
        /// <param name="value">Int16值</param>
        /// <returns>bit数组</returns>
        public static byte[] IntegerToBits(Int16 value)
        {
            return PrimitiveIntegerToBits(Convert.ToString(value, 2), sizeof(Int16));
        }


        /// <summary>
        /// UInt16转换为bit数组
        /// </summary>
        /// <param name="value">UInt16值</param>
        /// <returns>bit数组</returns>
        public static byte[] IntegerToBits(UInt16 value)
        {
            return PrimitiveIntegerToBits(Convert.ToString(value, 2), sizeof(UInt16));
        }


        /// <summary>
        /// Int32转换为bit数组
        /// </summary>
        /// <param name="value">Int32值</param>
        /// <returns>bit数组</returns>
        public static byte[] IntegerToBits(Int32 value)
        {
            return PrimitiveIntegerToBits(Convert.ToString(value, 2), sizeof(Int32));
        }

        /// <summary>
        /// Int64转换为bit数组
        /// </summary>
        /// <param name="value">Int64值</param>
        /// <returns>bit数组</returns>
        public static byte[] IntegerToBits(Int64 value)
        {
            return PrimitiveIntegerToBits(Convert.ToString(value, 2), sizeof(Int64));
        }

        /*
        /// <summary>
        /// UInt32转换为bit数组
        /// </summary>
        /// <param name="value">UInt32值</param>
        /// <returns>bit数组</returns>
        public static byte[] IntegerToBits(UInt64 value)
        {
            var high = (UInt32)(value >> 32);
            var low = (UInt32)(value << 32) >> 32;

            byte[] higBits = PrimitiveIntegerToBits(Convert.ToString(high, 2), sizeof(UInt32));
            byte[] lowBits = PrimitiveIntegerToBits(Convert.ToString(low, 2), sizeof(UInt32));
            byte[] bitValueArr = new byte[64];
            Array.Copy(higBits, bitValueArr, higBits.Length);
            Array.Copy(lowBits, 0, bitValueArr, higBits.Length, higBits.Length);
            return bitValueArr;
        }
        */

        private static byte[] PrimitiveIntegerToBits(string byteStr, int size)
        {
            int len = size * 8;//每字节8位
            if (byteStr.Length < len)
            {
                byteStr = byteStr.Insert(0, new string('0', len - byteStr.Length));
            }
            else if (byteStr.Length > len)
            {
                byteStr = byteStr.Substring(byteStr.Length - len);
            }

            byte[] bitValueArr = new byte[len];
            //int index = 0;
            //for (int i = len - 1; i >= 0; i--)
            //{
            //    bitValueArr[index] = byte.Parse(byteStr[i].ToString());
            //    index++;
            //}
            for (int i = 0; i < len; i++)
            {
                bitValueArr[i] = byte.Parse(byteStr[i].ToString());
            }

            return bitValueArr;
        }

        #endregion








        #region bit数组转换为整数
        /// <summary>
        /// bit数组转换为整数
        /// </summary>
        /// <typeparam name="T">目标类型</typeparam>
        /// <param name="bitValues">二进制位数组</param>
        /// <param name="offset">起始位置</param>
        /// <returns>转换结果</returns>
        /// <exception cref="NotSupportedException">非整数数据将抛出异常</exception>
        public static T BitsToInteger<T>(TypeCode typeCode, byte[] bitValues, int offset = 0)
        {
            if (bitValues == null)
            {
                throw new ArgumentNullException(nameof(bitValues));
            }

            object result;
            int count;
            const int FROM_BASE = 2;

            switch (typeCode)
            {
                case TypeCode.SByte:
                    count = 1;
                    if (bitValues.Length < count)
                    {
                        throw new ArgumentOutOfRangeException($"长度不能小于{count}");
                    }
                    result = Convert.ToSByte(string.Join(string.Empty, bitValues, offset, count), FROM_BASE);
                    break;
                case TypeCode.Byte:
                    count = 1;
                    if (bitValues.Length < count)
                    {
                        throw new ArgumentOutOfRangeException($"长度不能小于{count}");
                    }
                    result = Convert.ToByte(string.Join(string.Empty, bitValues, offset, count), FROM_BASE);
                    break;
                case TypeCode.Int16:
                    count = 2;
                    if (bitValues.Length < count)
                    {
                        throw new ArgumentOutOfRangeException($"长度不能小于{count}");
                    }
                    result = Convert.ToInt16(string.Join(string.Empty, bitValues, offset, count), FROM_BASE);
                    break;
                case TypeCode.UInt16:
                    count = 2;
                    if (bitValues.Length < count)
                    {
                        throw new ArgumentOutOfRangeException($"长度不能小于{count}");
                    }
                    result = Convert.ToUInt16(string.Join(string.Empty, bitValues, offset, count), FROM_BASE);
                    break;
                case TypeCode.Int32:
                    count = 4;
                    if (bitValues.Length < count)
                    {
                        throw new ArgumentOutOfRangeException($"长度不能小于{count}");
                    }
                    result = Convert.ToInt32(string.Join(string.Empty, bitValues, offset, count), FROM_BASE);
                    break;
                case TypeCode.UInt32:
                    count = 4;
                    if (bitValues.Length < count)
                    {
                        throw new ArgumentOutOfRangeException($"长度不能小于{count}");
                    }
                    result = Convert.ToUInt32(string.Join(string.Empty, bitValues, offset, count), FROM_BASE);
                    break;
                case TypeCode.Int64:
                    count = 8;
                    if (bitValues.Length < count)
                    {
                        throw new ArgumentOutOfRangeException($"长度不能小于{count}");
                    }
                    result = Convert.ToInt64(string.Join(string.Empty, bitValues, offset, count), FROM_BASE);
                    break;
                case TypeCode.UInt64:
                    count = 8;
                    if (bitValues.Length < count)
                    {
                        throw new ArgumentOutOfRangeException($"长度不能小于{count}");
                    }
                    result = Convert.ToUInt64(string.Join(string.Empty, bitValues, offset, count), FROM_BASE);
                    break;
                default:
                    throw new NotSupportedException($"不支持二进制位转换为类型\"{typeCode}\"");
            }

            return (T)result;
        }


        /* bit位操作demo代码
        private static void TestBitOperations()
        {
            bool ret1 = BitOperations.IsPow2(8);
            bool ret2 = BitOperations.IsPow2(7);
            bool ret3 = BitOperations.IsPow2(4);


            UInt32 uint32 = 16;
            int count = BitOperations.LeadingZeroCount(uint32);
        }

        private static void TestBitArray()
        {
            int length = 32;
            StringBuilder sb = new StringBuilder();

            BitArray bitArray = new BitArray(length, false);
            for (int i = 0; i < length; i++)
            {
                sb.Append(bitArray.Get(i));
            }
            string str1 = sb.ToString();
            bitArray.Set(0, true);
            bitArray.Set(1, true);
            bitArray.Set(15, true);

            sb.Clear();
            for (int i = 0; i < length; i++)
            {
                sb.Append(bitArray.Get(i) ? "01" : "00");
            }
            string str2 = sb.ToString();
            byte[] buffer = StringEx.HexadecimaStringToBytes(str2, false);
            int ret = NumberEx.BitsToInteger<Int32>(buffer);
        }

        private static void TestBitVector32()
        {
            int myBit1 = BitVector32.CreateMask();
            int myBit2 = BitVector32.CreateMask(myBit1);
            int myBit3 = BitVector32.CreateMask(myBit2);
            int myBit4 = BitVector32.CreateMask(myBit3);

            int index = 0;
            List<int> maskArr = new List<int>();
            for (int i = 0; i < 4; i++)
            {
                maskArr.Add((int)Math.Pow(2, index++));
            }

            int data1 = 0;
            BitVector32 myBV = new BitVector32(data1);
            string str1 = myBV.ToString();

            foreach (int mask in maskArr)
            {
                myBV[mask] = true;
            }
            //myBV[myBit1] = true;
            //myBV[myBit2] = true;
            //myBV[myBit3] = true;
            //myBV[myBit4] = true;

            string str2 = myBV.ToString();
            int retData = myBV.Data;
        }


        private static void TestHalf()
        {
            Span<byte> span = new Span<byte>();
            Half half = BinaryPrimitives.ReadHalfLittleEndian(span);

            Half val = (Half)123.456;
            val = new Half();
        }

        */
        #endregion

        #endregion

    }
}
